home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #1 / Amiga Plus 1999 #1.iso / System-Boost / Workbench / LFSystemBinder / compagnons / Registry / Examples / TestResource.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-21  |  2.1 KB  |  87 lines

  1. /*
  2.  *  TestResource.c
  3.  *      © LFSoft 1995
  4.  *
  5.  *      This code is fully a dommain public: Use it as you want...
  6.  *
  7.  *  Test resources registering and notifications.
  8.  *
  9.  *  22/07/1995  First version
  10.  *  29/07/1995  Add sharing
  11.  *
  12.  *   Note:
  13.  *       * All libraries (but registery.library) are openned and closed
  14.  *   automaticaly by DICE's autoinit feature. You must add some code for
  15.  *   others compilers.
  16.  */
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/registry.h>
  20. #include <dos/dos.h>    // CTRL-C
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. struct Library *RegistryBase=NULL;
  25.  
  26. APTR resid=NULL;    // resource id
  27. char opt;
  28. BOOL succ= FALSE;
  29.  
  30. void lib( void ){   // Free allocated resources
  31.     if(RegistryBase){
  32.         switch(opt){    // According to the used option
  33.         case 'l':
  34.         case 's':
  35.             if(succ)
  36.                 RL_UnLockResource(resid); break;
  37.         case 'd':
  38.             RL_EnableNotifying(resid); break;
  39.         }
  40.         RL_UnRegisterResource(resid);
  41.         CloseLibrary(RegistryBase);
  42.     }
  43. }
  44.  
  45. void main(int ac, char **av){
  46.     opt=FALSE;
  47.  
  48.     if(ac>1) opt = (*av[1] == '-');
  49.  
  50.     if(ac < (opt?3:2) ){ // Some help ?
  51.         puts("Usage :\n\tTestResource [-l] Nom\n"
  52.             "Options:\n"
  53.             "\t-l Exclusively Lock this resource\n"
  54.             "\t-s Share this resource\n"
  55.             "\t-d Desable notification\n"
  56.             "\t-n Notify\n"
  57.             );
  58.         exit(10);
  59.     }
  60.  
  61.     if(!(RegistryBase = OpenLibrary("registry.library",0))){
  62.         puts("Can't open registry.library");
  63.         exit(20);
  64.     }
  65.     atexit(lib);
  66.  
  67.     printf("-> %08x\n",resid=RL_RegisterResource(av[opt?2:1]));
  68.  
  69.     if(opt) switch(opt=av[1][1]){
  70.         case 'l':
  71.             printf("Locking -> %d\n",succ=RL_LockResource(resid,FALSE)); break;
  72.         case 's':
  73.             printf("Sharing -> %d\n",succ=RL_LockResource(resid,TRUE)); break;
  74.         case 'd':
  75.             RL_DisableNotifying(resid); break;
  76.         case 'n':
  77.             RL_Notify(resid); break;
  78.         default:
  79.             puts("Unsupported option");
  80.             exit(0);
  81.     }
  82.  
  83.     puts("CTRL-C to exit");
  84.     Wait(SIGBREAKF_CTRL_C);
  85.     exit(0);
  86. }
  87.